/**
 * Created by Administrator on 2022/8/24.
 */
/*class Animal {
    public String name = "阿黄";
    public int age;
    public String gerden = "男";

    public void eat() {
        this.name = name;
        System.out.println(name+"吃饭饭");
    }
}

class Dog extends Animal {
    public String name = "多多";
    public int age;
    public void eat() {
        System.out.println(name+"吃狗粮");
    }
}
public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog();
        animal.eat();
    }
}*/


/*
class Animal {
    public String name = "阿黄";
    public int age;
    public String gerden = "男";

    public void eat() {
        this.name = name;
        System.out.println(name+"吃饭饭");
    }
}

class Dog extends Animal {
    public void eat() {
        System.out.println(name+"吃狗粮");
    }
}
class Cat extends Animal {
    public void eat() {
        System.out.println(name+"吃猫粮");
    }
}
public class Test {
    public static void fun(Animal animal) {
        animal.eat();
    }
    public static void main(String[] args) {
        fun(new Dog());
        fun(new Cat());
    }
}*/


class Animal {
    public String name = "阿黄";
    public int age;
    public String gerden = "男";

    public void eat() {
        this.name = name;
        System.out.println(name+"吃饭饭");
    }
}

class Dog extends Animal {
    public void eat() {
        System.out.println(name+"吃狗粮");
    }
}

class Cat extends Animal {
    public void eat() {
        System.out.println(name+"吃猫粮");
    }
}

public class Test {
    public static void main(String[] args) {
        /*Animal animal = new Dog();
        Dog dog = (Dog) animal;
        dog.eat();*/

        Animal animal = new Cat();
        if (animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.eat();
        }

    }
}
